package router

import (
	"crow-k8s/src/config"
	"crow-k8s/src/service"
	"github.com/gin-gonic/gin"
)

// GetNodeList 查看node列表
// @Summary 查看node列表
// @Description 查看node列表
// @Tags Node
// @Success 200 {object} response.Response{data=v1.NodeList} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/k8s/node/list [get]
// @Security Bearer
func GetNodeList(c *gin.Context) {
	nodeList, err := service.GetNodeList(config.K8sClientSet)
	for err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, nodeList)
}

// GetNode 查看指定node
// @Summary 查看指定node
// @Description 查看指定node
// @Tags Node
// @Param node_name query string true "node_name名字"
// @Success 200 {object} response.Response{data=v1.Node} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/k8s/node [get]
// @Security Bearer
func GetNode(c *gin.Context) {
	nodeName := c.Query("node_name")
	nodeInfo, err := service.GetNode(config.K8sClientSet, nodeName)
	for err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, nodeInfo)
}
